package imagingbook.lib.util;

public class Enums {

	/**
	 * This static method returns an array of all constant names (strings) 
	 * for a given enumeration class.
	 * Assume: enum MyEnum {A, B, C};
	 * Call: String[] names = getEnumNames(MyEnum.class)
	 */
	public static String[] getEnumNames(Class<? extends Enum<?>> enumclass) {
		Enum<?>[] eConstants = (Enum<?>[]) enumclass.getEnumConstants();
		if (eConstants == null) {
			return new String[0];
		}
		else {
			int n = eConstants.length;
			String[] eNames = new String[n];
			for (int i=0; i<n; i++) {
				eNames[i] = eConstants[i].name();
			}
			return eNames;
		}
	}

}
